<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>电子文档系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="view/jquery/jquery-1.9.1.js"></script>
	<link rel="stylesheet" href="view/toastr/toastr.css">
	<script type="text/javascript" src="view/js/docMan.js"></script>
	<script type="text/javascript" src="view/bootstrap/js/bootstrap.js"></script>
	<link rel="stylesheet" href="view/bootstrap/css/bootstrap.css">
	<script type="text/javascript" src="view/toastr/toastr.min.js"></script>
	<link rel="stylesheet" href="view/css/docMan.css">
  </head>
  
  <body style="background: #EDEFF0;">
  	<div id="main-container" class="container" style="height: 100%;width:90%;background: #ffffff">
  		<div class="row" style="height: 100%">
  			<!-- <div id="left-p" class="col-sm-2" style="height: 100%;border-right: 1px solid #d2d2d2;"></div> -->
  			<div  class="col-sm-12" style="height: 100%;padding: 0px 30px 20px 30px;">
  				<div class="row mt_10" style="height:44px;width: 100%">
  					<!-- <form action="search.action" method="post" target="_blank"  style="width: 40%;display: inline;">
  						<input type="text" class="form-control" name="param" style="width: 10%;display: inline;">
  						<button class="btn btn-primary btn-search" type="submit">全文搜索</button>
  					</form> -->
  					<!-- <form action="pageSearch.action" method="post" target="_blank"  style="width: 40%;display: inline;">
  						<input type="text" class="form-control" name="pageLucene.searchText" style="width: 20%;display: inline;">
  						<input type="number" class="form-control" value="1" name="pageLucene.currentPage" style="display: none;">
  						<input type="number" class="form-control" value="0" name="pageLucene.beginIndex" style="display: none;">
  						<button class="btn btn-primary " type="submit">全文搜索</button>
  						开始<input type="date" name="pageLucene.startDate" style="margin-right:10px;margin-left:10px;padding:3px 4px;" />结束<input type="date" name="pageLucene.endDate" style="margin-left:10px;padding:3px 4px;"/>
  					</form> -->
  					<a class="btn btn-primary" href="searchIndex.action" style="margin-left:5%;" target="_blank">全文搜索</a>
  						<a class="btn btn-default" href="myFiles.action" style="margin-left:1%;" target="_blank">我的文件</a>
  						<a class="btn btn-default" href="gwll.action" style="margin-left:1%;" target="_blank">公文浏览</a>
  						<a class="btn btn-default" href="zywj.action" style="margin-left:1%;" target="_blank">重要文件</a>
  						<a class="btn btn-default" href="bookSonN.action" style="margin-left:1%;" target="_blank">资料浏览</a>
  					<form action="logout.action" method="post" style="width:20%;display: inline;float: right;">
  						当前登入：${session.humanName}<button type="submit" class="btn btn-link">退出</button>
  					</form>
  				</div>
  				<div class="row" style="height:44px;background: #F5F5F5">
  					<ol class="breadcrumb" style="padding: 12px 15px;">
						<li><a href="index.action" class="link">首页</a></li>
					</ol>
  				
  				</div>
  				<div class="row" style="height: 45px;">
  					<button id="btn-disc-refresh" class="btn btn-default mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;">刷新</button>
  					<s:if test="#session.admin==true">
  						<button id="btn-disc-creat-modal" class="btn btn-default mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;">创建</button>
  						<button id="btn-disc-manager" class="btn btn-primary mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;">管理</button>
  						<a id="btn-disc-book" target="_blank" href="book.action" class="btn btn-primary mt_10 ml_10" style="height: 25px;padding: 2px 12px 2px 12px;">书本</a>
  					</s:if>
  				</div>
  				<div class="row border_top disk_list">
	  				<s:iterator value="docDiscs" id="disc" status="stu">
	  					<div class="row margine_clear border_bottom disk">
	  						<div class="col-sm-3 textcenter padding_clear" style="width: 15%; margin: 8px 0px 7px 0px;">
	  							<i class="diskpic-folder"></i>
	  						</div>
	  						<div style="position: relative;float: left;width: 27%;margin: 8px 0px 7px 0px;font-size:13px;">
	  							<div>
	  								<a id="<s:property value="#disc.id" />" href='diskView.action?diskId=<s:property value="#disc.id" />'> <s:property value="#disc.name"/></a>
	  							</div>
	  							<div>
	  								<a href="javascript:void(0)" class="discAttr" id="<s:property value="#disc.id" />"  style="font-size: 12px;color: #06c;">查看属性</a>
	  							</div>
	  						</div>
	  					</div>
	  				</s:iterator>
  				</div>
  			</div>
  		</div>
  	</div>
	<div class="modal fade" id="discCreateModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">新建网盘</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<label for="discName" class="control-label">网盘名:</label>
							<input type="text" class="form-control" id="discName">
						</div>
						<div class="form-group">
							<label for="disDescr" class="control-label">所属部门:</label>
							<select class="form-control" id="disUnit">
								<option value="1" selected="selected"></option>
							</select>
						</div>
						<div class="form-group">
							<label for="disDescr" class="control-label">备注:</label>
							<input class="form-control" id="disDesc">
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" id="btn-disc-creat" class="btn btn-primary">创建</button>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="discAttrModal" tabindex="-1" role="dialog"  aria-hidden="false"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">网盘信息</h4>
				</div>
				<div class="modal-body">
					<div class="row" >
						<div class="col-xs-3">
							<div class="diskpic-file fr"></div>
						</div>
						<div class="col-xs-9 ">
							<input id="diskNameAttr" disabled="disabled" class="form-control" value='' >
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">占用空间：</span>
						</div>
						<div class="col-xs-9">
							<span id="diskSize"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">包含：</span>
						</div>
						<div class="col-xs-9">
							<span id="diskdirectoryContain"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">创建信息：</span>
						</div>
						<div class="col-xs-9">
							<span id="diskCreate"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">所属部门：</span>
						</div>
						<div class="col-xs-9">
							<span id="diskUnit"></span>
						</div>
					</div>
					<div class="row mt_5">
						<div class="col-xs-3 ">
							<span class="muted fr">备注：</span>
						</div>
						<div class="col-xs-9">
							<span id="diskDescription"></span>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" id="btn-directory-save" value="" class="btn btn-primary">保存</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
	
	<div class="modal fade" id="managerModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">管理</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="row">
							<div class="form-group col-xs-9">
								<label for="ftpIp" class="control-label">ftp的IP:</label>
								<input id="ftpIp" type="text" class="form-control" >
							</div>
							<div class="form-group col-xs-3">
								<label for="ftpPort" class="control-label">ftp的port:</label>
								<input id="ftpPort" type="number" class="form-control" >
							</div>
						</div>
						<div class=row>
							<div class="form-group col-xs-6">
								<label for="ftpUsername" class="control-label">用户名:</label>
								<input id="ftpUsername" type="text" class="form-control" />
							</div>
							<div class="form-group col-xs-6">
								<label for="ftpPassword" class="control-label">密码:</label>
								<input id="ftpPassword" type="text" class="form-control" value="" />
							</div>
						</div>
						<div id="inputHumanAttr" style="display: block;" class="row mt_5">
							<div class="col-xs-2 ">
								<span class=" ">管理员：</span>
							</div>
							<div class="col-xs-9">
								<input id="humanNameAttr"
								style="width:58%" class="col-xs-7 form-control">
							<button id="btn-add-humanAttr" type="button"
								class="btn btn-default ml_10">添加</button>
							</div>
						</div>
						<div id="humanNamesAttr" class="row " style="padding:0px 30px;">
							<%-- <div class="human_tag">
								<span style="width:60%;">潘善亮</span>
								<div class="human_tag_remove">
									<span class="glyphicon glyphicon-remove"
										style="font-size:2px;color:#fff;"></span>
								</div>
							</div> --%>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" id="btn-managerSave" class="btn btn-primary">保存</button>
				</div>
			</div>
		</div>
	</div>

</body>
  <script type="text/javascript">
  $(function(){
	  $("#btn-disc-creat-modal").on("click",function(){
		  $.ajax({
				 type:"get",
				 url:"/DocMan/webService/show/tcunit/getTopUnits",
				 success:function(data){
					 $(data["units"]).each(function(i,e){
						 var option="";
						 if(i==4){
							option="<option selected=\"selected\"  value=\""+e.unitId+"\">"+e.unitName+"</option>";
						 }else{
							 option="<option value=\""+e.unitId+"\">"+e.unitName+"</option>";
						 }
						 $("#disUnit").append(option);
					 });
					 console.info(data);
				 }
			  });
			$("#discCreateModal").modal('show');
	  });
	  $("#btn-disc-creat").on("click",function(){
		  var discName=$("#discName").val();
		  var discDesc=$("#disDesc").val();
		  var unitId=$("#disUnit").children('option:selected').val(); 
		  $.ajax({
			 type:"post",
			 url:"/DocMan/webService/show/DocDisc/saveOrUpdate",
			 data:{name:discName,desc:discDesc,unitId:unitId},
			 success:function(data){
				 console.info(data);
				 if(data["success"]){
					 var disk="<div class=\"row margine_clear border_bottom disk\">"+
									"<div class=\"col-sm-3 textcenter padding_clear\" style=\"width: 15%; margin: 8px 0px 7px 0px;\">"+
										"<i class=\"diskpic-folder\"></i>"+
									"</div>"+
									"<div style=\"position: relative;float: left;width: 27%;margin: 8px 0px 7px 0px;font-size:13px;\">"+
										"<div>"+
											"<a id=\""+data["disk"].id+"\" href='diskView.action?diskId="+data["disk"].id+"'>"+data["disk"].name+" </a>"+
										"</div>"+
										"<div>"+
											"<a href=\"javascript:void(0) \" class=\"discAttr\" id=\""+data["disk"].id+"\"  style=\"font-size: 12px;color: #06c;\">查看属性</a>"+
										"</div>"+
									"</div>"+
							  "</div>";
					 $(".disk_list").append(disk);
				 }else{
					 toast.error("你不是管理员", "温馨提示");
					 
				 }
				 $("#discCreateModal").modal('hide');
			 },
			 error:function(data){
				 toast.error("创建网盘错误", "温馨提示");
			 }
		  });
	  });
	 /*  $.ajax({
		 type:"post",
		 url:"/DocMan/webService/show/FTP/getFtpFile",
		 success:function(data){
			 console.info(data);
		 }
	  }); */
	  $(".disk_list").on("click",".discAttr",function(){
		  var id=$(this).attr("id");
		  $.ajax({
				 type:"post",
				 url:"/DocMan/webService/show/DocDisc/getDisk",
				 data:{diskId:id},
				 success:function(data){
					 console.info(data);
					 $("#diskNameAttr").val(data["docDisk"].name);
					 $("#diskSize").html(data["docDisk"].large+"MB");
					 $("#diskdirectoryContain").html(data["docDisk"].fileCount+"个文件，"+data["docDisk"].directoryCount+"个文件夹");
					 $("#diskCreate").html(data["docDisk"].humanName+"&nbsp;"+string.dateFormat(data["docDisk"].createTime, "yyyy-MM-dd hh:mm"));
					 $("#diskUnit").html(data["unit"].unitName);
					 $("#diskDescription").html(data["docDisk"].description);
					 $("#discAttrModal").modal("show");
				 },
				 error:function(data){
					 
				 }
			  });
	  });
	  $("#btn-disc-manager").on("click",function(){
		  $.ajax({
				 type:"post",
				 url:"/DocMan/webService/show/docAdmin/getAdmins",
				 success:function(data){
					 if(data["success"]){
						 console.info(data);
						 $("#ftpIp").val(data["url"]);
						 $("#ftpPort").val(data["port"]);
						 $("#ftpUsername").val(data["username"]);
						 $("#ftpPassword").val(data["password"]);
						 $("#humanNamesAttr").find(".human_tag").remove();
						 $(data["tchumans"]).each(function(i,e){
							 var humanTag="<div id=\""+e.humanid+"\" class=\"human_tag\">"+
												"<span style=\"width:60%;\">"+e.humanname+"</span>"+
												"<div class=\"human_tag_remove\">"+
													"<span class=\"glyphicon glyphicon-remove\" style=\"font-size:2px;color:#fff;\"></span>"+
												"</div>"+
											"</div>";
							  $("#humanNamesAttr").append(humanTag);
						 });
					 }else{
						 toast.error("你还不是管理员，无法进行管理", "温馨提示");
					 }
				 },
				 error:function(data){
				 }
			  });
		 $("#managerModal").modal("show");
	  });
	  $("#btn-managerSave").on("click",function(){
		 var ip= $("#ftpIp").val();
		 var port=$("#ftpPort").val();
		 var username=$("#ftpUsername").val();
		 var password=$("#ftpPassword").val();
		 var humanIds=new Array();
		$($("#humanNamesAttr").find(".human_tag")).each(function(i,e){
			humanIds[i]=$(this).attr('id');
		});
		 $.ajax({
			 type:"post",
			 url:"/DocMan/webService/show/docAdmin/saveAdmins",
			 traditional:true,
			 data:{ip:ip,username:username,password:password,port:port,humanIds:humanIds},
			 success:function(data){
				 $("#managerModal").modal("hide");
			 },
			 error:function(data){
				 
			 }
		  });
	  });
  });
  
  </script>
</html>
